package org.wzl.personalwebsite.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.wzl.personalwebsite.dto.RegisterDTO;
import org.wzl.personalwebsite.dto.UserLoginDTO;
import org.wzl.personalwebsite.service.UserService;
import org.wzl.personalwebsite.utils.Resp;

/**
 * @author 卫志龙
 * @version 1.0
 * @date 2024/9/21 20:28
 */
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 注册接口
     *
     * @param: [userLoginDTO, request]
     * @return: org.wzl.personalwebsite.utils.Resp<?>
     * @author 卫志龙
     * @date: 2024/9/21 23:49
     */
    @PostMapping("/login")
    public Resp<?> login(@RequestBody UserLoginDTO userLoginDTO,
                         HttpServletRequest request) {
        userService.login(userLoginDTO, request);
        return Resp.ok();
    }

    @GetMapping("/getRegisterVerifyImg")
    public Resp<?> getRegisterVerifyImg() {
        return Resp.ok(userService.getRegisterVerifyImg());
    }


    @PostMapping("/register")
    public Resp<?> register(@RequestBody RegisterDTO registerDTO) {
        userService.register(registerDTO);
        return Resp.ok();
    }

}
